﻿using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace CentroVentas.Clases
{
    class Reportes
    {

        public static void MostrarCompra(int IdCompra,CrystalDecisions.Windows.Forms.CrystalReportViewer crv) 
        {
            ReportDocument rpt = new ReportDocument();
            rpt.Load(Application.StartupPath + "\\Model\\Reportes\\RptCompra.rpt");

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = IdCompra;
            crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["idCompra"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crv.ReportSource = rpt;
        }

        public static void ImprimirCompra(int IdCompra){
            // REPORTE

            ReportDocument rpt = new ReportDocument();
            rpt.Load(Application.StartupPath + "\\Model\\Reportes\\RptCompra.rpt");

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            
            crParameterDiscreteValue.Value = IdCompra;
            crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["idCompra"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            rpt.PrintToPrinter(1, false, 0, 0);
        }

        public static void ImprimirVenta(int IdVenta)
        {
            // REPORTE

            ReportDocument rpt = new ReportDocument();
            rpt.Load(Application.StartupPath + "\\Model\\Reportes\\RptComprobantePago.rpt");

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = IdVenta;
            crParameterFieldDefinitions = rpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["IdVenta"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            rpt.PrintToPrinter(1, false, 0, 0);
        }

    }
}
